import React from 'react';
import { Form, Input, Button, message, Space } from 'antd';
import { connect } from 'umi';
import request from '@/utils/request';
import { ArrowRightOutlined } from '@ant-design/icons';

const apiURL = '/api/services/app/AuthCards/';
class PswUpdate extends React.Component<any, any> {
    constructor(props: any) {
        super(props);
        this.state = {
            loading: false,
            datas: {},
        }
    }
    formRef: any = React.createRef();
    componentDidMount() {
    }
    onFinish = (values: any) => {
        this.setState({ loading: true });
        request(apiURL + 'DoAuth', {
            method: 'POST',
            params: values,
        }).then((response) => {
            if (response) {
                if (response.success) {
                    if (response.result == 0)
                        message.warning('授权码不存在');
                    else if (response.result == 1)
                        message.error('授权密钥错误');
                    else if (response.result == 3)
                        message.warning('授权码已使用');
                    else
                        message.info('授权成功');
                } else {
                    message.error(response.error.message);
                }
                this.setState({ loading: false });
            }
        });
    };

    render() {
        const layout = {
            labelCol: { span: 6 },
            wrapperCol: { span: 17 },
        };
        return (
            <div>
                <Form {...layout} ref={this.formRef} onFinish={this.onFinish} >
                    <Form.Item
                        name='cardNo'
                        label="授权码"
                        rules={[{ required: true, message: "请输入授权码" }]}>
                        <Input />
                    </Form.Item>
                    <Form.Item
                        name='cardPwd'
                        label="密钥"
                        rules={[{ required: true, message: "请输入授权密钥" }]}
                    >
                        <Input.Password />
                    </Form.Item>
                    <Form.Item wrapperCol={{ ...layout.wrapperCol, offset: 6 }}>
                        <Space>
                            <Button
                                type="primary"
                                htmlType="submit"
                                loading={this.state.loading}
                            >确定</Button>
                            <a href="https://dwz.cn/AjbeMkcN" target="_blank"><ArrowRightOutlined /> 购买激活码</a>
                        </Space>
                    </Form.Item>
                </Form>
            </div>
        )
    }
}
export default connect(({ Abp }: API.IConnectState) => ({
    Abp,
    response: Abp.response,
    currentUser: Abp.currentUser
}))(PswUpdate);